import pika
# pipreqs . --encoding=utf8 --force
# # 建立到RabbitMQ服务器的连接
# userinfo = pika.PlainCredentials('admin','Huisonglin1993')
# connection = pika.BlockingConnection(pika.ConnectionParameters('8.142.208.28','5673','xinnuo',userinfo))
# channel = connection.channel()
#
# # 创建一个名为hello的队列
# channel.queue_declare(queue='hello')
#
# # 发送一条消息到hello队列
# channel.basic_publish(exchange='',
#                       routing_key='hello',
#                       body='Hello World!')
# print(" [x] Sent 'Hello World!'")
#
# # 关闭连接
# connection.close()

# 建立到RabbitMQ服务器的连接
userinfo = pika.PlainCredentials('admin','Huisonglin1993')
connection = pika.BlockingConnection(pika.ConnectionParameters('8.142.208.28','5673','xinnuo',userinfo))
channel = connection.channel()

def callback(ch,method,properties,body):
    print(f" [x] Received {body}")


# 告诉RabbitMQ，当从hello队列中收到消息时，调用callback函数
channel.basic_consume(queue='bicycle_asx', on_message_callback=callback, auto_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()

